package ex;

import java.util.*;

/**
 * @author: knowno
 * @create: 2025-09-16 10:23
 * @Version 1.0
 **/
public class TestHashMap {
    public static void main(String[] args) {
        //
        HashMap map = new HashMap<>();
        map.put("100","a");
        map.put("200","b");
        map.put("300","c");
        //key是否允许重复 => 不允许重复，后一个值会覆盖前一个值
        map.put("100","ccc");
        //是否允许为null
        map.put(null,null);

        //输出
        System.out.println(map);
        //三类获取集合元素  key集合  keySet ,value集合  key-value集合
        Set keySet = map.keySet();
        System.out.println(keySet);
        Collection values = map.values();
        System.out.println(values);
        Set<Map.Entry<String,String>> entrySet = map.entrySet();
        System.out.println(entrySet);

        //通过key获取value
        Iterator iterator = keySet.iterator();
        while (iterator.hasNext()){
            Object key = iterator.next();
            System.out.println("key:"+key+" value:"+map.get(key));
        }



    }
}
